// ==UserScript==
// @name          Trade helper for exchange.bitparking.com
// @namespace     tradehelper-exchange.bitparking.com
// @version       0.1b
// @description   A Greasemonkey script that add button to calculate buy/sell amount for full deposit
// @include       https://exchange.bitparking.com/trade
// ==/UserScript==

try{(function()
{
// add iframe
var i=document.createElement('iframe');
i.setAttribute('id','if1');
i.setAttribute('src','https://exchange.bitparking.com/main');
i.setAttribute('style','position:absolute;top:380px;left:5px;width:98%;height:2000px');
var tags=document.getElementsByTagName('BODY');
tags[0].appendChild(i);

// move elements
var tags=document.getElementsByTagName('H2');
tags[0].setAttribute('style',"position:absolute;top:80px;");
tags[1].setAttribute('style',"position:absolute;top:80px;left:650px");
tags[2].setAttribute('style',"position:absolute;left:1220px;top:80px;");
var tags=document.getElementsByTagName('TABLE');
tags[0].setAttribute('style',"position:absolute;top:150px;");
tags[1].setAttribute('style',"position:absolute;top:150px;left:650px");
tags[2].setAttribute('style',"position:absolute;left:1220px;top:150px;");

var tags=document.getElementsByTagName('INPUT');
var cnt=0;
for(var t in tags) if(t!='length'&&t!='item'&&tags[t].getAttribute('type')=='submit') switch(cnt++)
{
	case 0:tags[t].setAttribute('style',"position:absolute;left:60px;top:330px;");break;
	case 1:tags[t].setAttribute('style',"position:absolute;left:170px;top:330px;");break;
	case 2:tags[t].setAttribute('style',"position:absolute;left:660px;top:330px;");break;
	case 3:tags[t].setAttribute('style',"position:absolute;left:770px;top:330px;");break;
}

var i=document.createElement('input');
i.setAttribute('type','button');
i.setAttribute('value','full amount');
i.setAttribute('style','position:absolute;left:220px;top:330px;')
i.onclick=function()
{
	var btcs=document.forms[0].childNodes[2].childNodes[1].childNodes[0].childNodes[1].innerHTML;
	var btc_price=document.forms[0].childNodes[2].childNodes[1].childNodes[6].childNodes[1].childNodes[1].value;
	document.forms[0].childNodes[2].childNodes[1].childNodes[4].childNodes[1].childNodes[1].value=Math.floor(10000*btcs/(1.002*btc_price))/10000;
}
document.forms[0].appendChild(i);

var i=document.createElement('input');
i.setAttribute('type','button');
i.setAttribute('value','full amount');
i.setAttribute('style','position:absolute;left:820px;top:330px;')
i.onclick=function()
{
	var btcs=document.forms[1].childNodes[2].childNodes[1].childNodes[0].childNodes[1].innerHTML;
	var btc_price=document.forms[1].childNodes[2].childNodes[1].childNodes[6].childNodes[1].childNodes[1].value;
	document.forms[1].childNodes[2].childNodes[1].childNodes[4].childNodes[1].childNodes[1].value=Math.floor(100000*btcs/1.002)/100000;
}
document.forms[1].appendChild(i);

setInterval(function(){var f=document.getElementById('if1');f.src=f.src;},2*60*1000);

})()}catch(e){};

